<template>
	<view style="display: flex;flex-direction: column;height: 100vh;">
		<u-navbar :placeholder="true" title="微聊" :bgColor="'#e9e9ea'" :autoBack="true" :border="true" z-index="10076">
			<view slot="center" style="color: #000;font-size: 30rpx;">
				添加联系人{{istrue}}
			</view>
		</u-navbar>
		<view style="flex: 1;overflow: hidden;">
			<view style="display: flex;padding: 25rpx;">
				<u-avatar shape="square" src=""></u-avatar>
				<view style="flex: 1;padding-left: 20rpx;display: flex;font-size: 28rpx;flex-direction: column;">
					<text style="font-weight: bold;font-size: 28rpx;">{{obj.Username}}</text>
					<text v-if="istrue">昵称：{{data.Nickname?data.Nickname:'--'}}</text>
					<text v-if="istrue">添加时间：{{data.CreatedAt?$u.timeFormat(new Date(data.CreatedAt).getTime(), 'yyyy年mm月dd日 hh时MM分ss秒'):'--'}}</text>
				</view>
			</view>
			<u-cell-group>
				<u-cell icon="setting-fill" :icon="''" title="来源" value="来自用户搜索"></u-cell>
				<u-cell icon="integral-fill" :icon="''" title="手机号" :value="obj.Phone"></u-cell>
				<u-cell icon="integral-fill" :icon="''" title="签名" :value="obj.Desc?obj.Desc:'未设置'"></u-cell>
			</u-cell-group>

			<u-button text="添加用户" v-if="!istrue" @click="adduser"
				style="border-radius: 0;margin-top: 40rpx;border-left: 0;border-right: 0;"></u-button>
			<u-button @click="$u.route({url:'pages/chat/chat',params:obj})" text="发信息" v-else style="border-radius: 0;margin-top: 40rpx;border-left: 0;border-right: 0;">
			</u-button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				obj: {},
				istrue: false,
				data: {}
			};
		},
		methods: {
			adduser() {
				var data = {
					"Cid": this.$userInfo.ID,
					"Fid": Number(this.obj.ID),
					"Type": "",
					"Topimg": this.obj.Top,
					"Content": "",
					"Other": "",
					"Username": this.obj.Username,
					"Phone": this.obj.Phone,
					"Name": "",
					"Datatype": 'addcontact',
					"Msg": ''
				}
				uni.$emit("sendSocketMessage", data)
			},
			getdata() {
				uni.$u.http.get('/getUsersis', {
					params: {
						key: this.obj.Phone
					}
				}, {}).then(res => {
					if (res.state == 200) {
						this.istrue = res.istrue === 0 ? false : true;
						this.data = res.data
						return;
					}
					// uni.savedata()
					uni.showToast({
						title: res.msg,
						icon: "none",
						mask: true,
						duration: 2000,
					})
				}).catch(err => {
					console.log(err)
				})
			}
		},

		onLoad(e) {
			console.log(e)
			this.obj = e;
			this.getdata()
		}
	}
</script>

<style lang="scss">

</style>
